<?php
/**
 * created by zzy
 * date: 2017/10/24 9:28
 */

namespace App\Api\Service\AppIndex\Controllers;

use Framework\BaseClass\Api\Controller;
use App\Eloquent\Ygt\Appindex;
use App\Eloquent\Ygt\Privilege;
use App\Eloquent\Ygt\DepartmentUser;
use App\Engine\Func;

class IndexController extends Controller
{

    public function index(){
        $result         = Appindex::getListByPid( 0 );
        return $result;
    }
    public function user(){

        $user_id        = Func::getHeaderValueByName( 'userid',1 );
        $info           = DepartmentUser::getCurrentInfo( $user_id );
        if( !$info ){
            xThrow( ERR_PARAMETER );
        }
        $privilege_id   = $info->privilege_id;
        $companyId      = $info->company_id;
        $lists          = Privilege::getAppindexList( $privilege_id );
        $result         = [];
        if( $lists->isNotEmpty() ){
            $lists_arr                      = $lists->toArray();
            foreach( $lists_arr as $key=>$val ){
                $img_url                    = $img_url_active = '';
                if( $val['img_url'] ){
                    $img_url                = asset( $val['img_url'] );
                }
                if( $val['img_url'] ){
                    $img_url_active         = asset( $val['img_url_active'] );
                }
                $arr                        = $val;
                unset( $arr['id'] );
                $arr['img_url']            = $img_url;
                $arr['img_url_active']    = $img_url_active;
                $arr['is_show_help']      = $val['is_show_help'];
                $arr['help_href']         = asset($val['help_href']);

                $result[]                   = $arr;
            }
        }

        return $result;
    }


}